INSTALL_TOP = /usr/local
INSTALL_INC = $(INSTALL_TOP)/include
INSTALL_LIB = $(INSTALL_TOP)/lib

MKDIR = mkdir -p -m 0755
RMDIR = rmdir -p --ignore-fail-on-non-empty

INSTALL = install -p
INSTALL_EXEC = $(INSTALL) -m 0755
INSTALL_DATA = $(INSTALL) -m 0644

TO_INC = event2/helper.h event2/session.h event2/acceptor.h
TO_LIB = libevent_helper.so

all clean:
	cd src && $(MAKE) $@
	cd sample && $(MAKE) $@

install:
	cd src && $(MKDIR) $(INSTALL_INC)/event2 $(INSTALL_LIB)
	cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)/event2
	cd src && $(INSTALL_EXEC) $(TO_LIB) $(INSTALL_LIB)

uninstall:
	cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
	cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
	cd src && $(RMDIR) $(INSTALL_INC)/event2 $(INSTALL_LIB)

.PHONY: all clean install uninstall
